import { ILv70DramaStepCommand } from "../interfaces/ILv70DramaStepCommand";
import { TDrama } from "../../../../../Message/Db/Tables/TDrama";
import { Lv70NpcTalkData } from "../data/Lv70NpcTalkData";
import { Global } from "../../../../../com/gengine/global/Global";
import { LayerManager } from "../../../manager/LayerManager";
import { Lv70NpcTalkMaskText } from "./npctalk/Lv70NpcTalkMaskText";
import { Lv70OpBlackScreen } from "./Lv70OpBlackScreen";
//class Lv70OpBlackScreenThenTips
    
    export  class Lv70OpBlackScreenThenTips implements ILv70DramaStepCommand
    {
        

        public dispose(): void
        {
            if (this._blacker != null) 
            {
                this._blacker.dispose();
                this._blacker = null;
            }
            if (this._maskText != null) 
            {
                this._maskText.dispose();
            }
            return;
        }

        public call(arg1: TDrama, arg2: Function=null): void
        {
            var config: TDrama;
            var callback: Function=null;
            var tips: string;
            var showTime: number;
            var data: Lv70NpcTalkData;
            var onEnd: Function;

            var loc1;
            data = null;
            onEnd = null;
            config = arg1;
            callback = arg2;
            onEnd = (): void
            {
                if (_maskText.parent != null) 
                {
                    _maskText.parent.removeChild(_maskText);
                }
                if (callback != null) 
                {
                    callback.apply();
                }
                return;
            }
            tips = config.text;
            showTime = 2800;
            if (!this._isInited) 
            {
                this.init();
                this._isInited = true;
            }
            data = this.getNpcTalkData(tips, showTime);
            this._maskText.x = (Global.stage.stageWidth - data.rowWidth) / 2;
            this._maskText.y = Global.stage.stageHeight / 2 - 50;
            LayerManager.highestLayer.addChild(this._maskText);
            this._maskText.show(data, onEnd);
            return;
        }

        public cancel(arg1: TDrama, arg2: Function=null): void
        {
            this.blacker.cancel(arg1);
            if (this._maskText.parent != null) 
            {
                this._maskText.parent.removeChild(this._maskText);
            }
            if (arg2 != null) 
            {
                arg2.apply();
            }
            return;
        }

        /* internal  */getNpcTalkData(arg1: string, arg2: number): Lv70NpcTalkData
        {
            var loc1=new Lv70NpcTalkData();
            loc1.popupTime = 0;
            loc1.rowWidth = Math.min(Global.stage.stageWidth, 800);
            loc1.showTime = arg2;
            loc1.speed = 5;
            loc1.talk = arg1;
            loc1.talkFontLeading = 6;
            loc1.talkFontSize = 24;
            return loc1;
        }

        /* internal  */init(): void
        {
            this._maskText = new Lv70NpcTalkMaskText();
            return;
        }

        public get blacker(): Lv70OpBlackScreen
        {
            if (this._blacker == null) 
            {
                this._blacker = new Lv70OpBlackScreen();
            }
            return this._blacker;
        }

        public set blacker(arg1: Lv70OpBlackScreen)
        {
            this._blacker = arg1;
            return;
        }

        /* internal */ /* var */_blacker: Lv70OpBlackScreen;

        /* internal */ /* var */_isInited: Boolean;

        /* internal */ /* var */_maskText: Lv70NpcTalkMaskText;
    }
